<?php
namespace app\Admin\controller\user;

//引入公共控制器
use app\common\controller\Backend;


class Recharge extends Backend
{
     
    
    public function __construct(){

        //继承父类
        parent::__construct();

        $this->UserModel = model('User.User');
        $this->RecordModel = model('User.Record');
    
    }   
    
    

    // 充值记录
    public function recharge(){

        $where['state'] = ['=', '3'];

        $count = $this->RecordModel->where($where)->count();

        $countlist = $this->RecordModel->where($where)->order('createtime', 'desc')->paginate(10);

        foreach ($countlist as $key => $item) {
            switch ($item['state']) {
                case 1:
                    $item['state'] = '发布';
                    $item['point'] = '-' . $item['point'];
                    break;
                case 2:
                    $item['state'] = '采纳';
                    $item['point'] = '+' . $item['point'];
                    break;
                case 3:
                    $item['state'] = '充值';
                    $item['point'] = '+' . $item['point'];

                    break;
                case 4:
                    $item['state'] = '签到';
                    $item['point'] = '+' . $item['point'];

                    break;
                case 5:
                    $item['state'] = '下商品订单';
                    $item['point'] = '-' . $item['point'];

                    break;
                case 6:
                    $item['state'] = '下预约订单';
                    $item['point'] = '-' . $item['point'];

                    break;
                case -1:
                    $item['state'] = '退款';
                    $item['point'] = '+' . $item['point'];

                    break;
                default:
                    break;
            }
        }


        $pagestr = $countlist->render();

        // var_dump($countlist);
        // exit;

        $this->assign([
            'count' => $count,
            'countlist' => $countlist,
            'pagestr' => $pagestr
        ]);

        return $this->fetch();
    }

    public function del()
    {
        if ($this->request->isPost()) {

            $success = [
                'result' => false,
                'msg' => ''
            ];

            $ids = $this->request->param('ids', 0);

            $result = $this->RecordModel->destroy($ids);


            if ($result === FALSE) {
                $success['result'] = false;
                $success['msg'] = $this->RecordModel->getError();
            } else {
                $success['result'] = true;
                $success['msg'] = '删除成功';
            }

            return json($success);
        }
    }

}